package com.ruoyi.car.controller.parts;

import com.car.pojo.Result;
import com.car.pojo.TbPartTerminalInformation;
import com.car.pojo.TbPartTerminalType;
import com.ruoyi.car.service.parts.ITbPartTerminalTypeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 车载终端型号控制类
 */
@Controller
@RequestMapping("/terminalType")
public class TbPartTerminalTypeController extends BaseController {
    @Autowired
    private ITbPartTerminalTypeService terminalTypeService;

    private String prefix = "system/carparts/terminal";

    @RequiresPermissions("carparts:terminal:view")
    @GetMapping()
    public String information()
    {
        return prefix + "/terminal";
    }
    /**
     * 模糊查询：终端型号名称、终端型号编号、终端种类
     * @return
     */
    @ResponseBody
    @PostMapping("/terminalTypeList")
    public TableDataInfo terminalTypeList(TbPartTerminalType tbPartTerminalType){
        startPage();
        List<TbPartTerminalType> tbPartTerminalTypes = (List<TbPartTerminalType>) this.terminalTypeService.terminalTypeList(tbPartTerminalType.getTerminalModelName(), tbPartTerminalType.getTerminalModelId(), tbPartTerminalType.getTerminalType());
        return getDataTable(tbPartTerminalTypes);
    }

    /**
     * 查询该数据下的车载详细信息
     * @param id
     * @return
     */
    @GetMapping("/terminalTypeById/{id}")
    @ResponseBody
    public TbPartTerminalType terminalTyperById(@PathVariable("id") Long id){
        return  this.terminalTypeService.terminalTypeById(id);
    }

    /**
     * 跳转新增页面
     * @param id
     * @param map
     * @return
     */
    @GetMapping("/add")
    public String add(){
        return prefix + "/add";
    }
    /**
     * 新增车载终端型号
     * @param tbPartTerminalType
     * @return
     */
    @PostMapping("/terminalTypeInsert")
    @ResponseBody
    public Result terminalTypeInsert(TbPartTerminalType tbPartTerminalType){
        try{
            this.terminalTypeService.terminalTypeInsert(tbPartTerminalType);
            return new Result("添加成功",true);
        }catch (Exception e){
            return new Result("添加失败",false);
        }
    }

    /**
     * 跳入车载终端型号编辑功能
     * @param id
     * @param map
     * @return
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap map){
        //回显数据
        TbPartTerminalType tbPartTerminalType = this.terminalTypeService.terminalTypeById(id);
        map.put("tbPartTerminalType",tbPartTerminalType);
        return prefix + "/edit";
    }
    /**
     * 完成车载终端信息编辑功能
     * @param tbPartTerminalType
     * @return
     */
    @RequestMapping("/terminalTypeUpdate/{id}")
    @ResponseBody
    public Result terminalTypeUpdate(TbPartTerminalType tbPartTerminalType){
        try{
            this.terminalTypeService.terminalTypeUpdate(tbPartTerminalType);
            return new Result("修改成功",true);
        }catch (Exception e){
            e.printStackTrace();
            return new Result("修改失败",false);
        }
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @PostMapping("/terminalTypeDelete")
    @ResponseBody
    public Result terminalTypeDelete(String[] ids){
        System.out.println(ids.toString());
        try{
            this.terminalTypeService.deleteTbPartSimRecordByIds(ids);
            return new Result("删除成功",true);
        }catch (Exception e){
            e.printStackTrace();
            return new Result("删除失败",false);
        }
    }
}
